// gulp的入口文件
const fs = require('fs');

exports.cb = done => {
  console.log(`cb`)
  done()
}

exports.cb_error = done => {
  console.log(`cb_error`)
  done(new Error('task error'))
}


exports.promise = () => {
  console.log(`promise task`)
  return Promise.resolve();
}

exports.promise_error = () => {
  console.log(`promise_error task`)
  return Promise.reject(new Error('promise task'));
}

const timeout = time => {
  return new Promise(resolve => {
    setTimeout(resolve, time);
  })
}

exports.async = async () => {
  await timeout(1000)
  console.log(`async task`)
}


exports.stream = () => {
  const readStream = fs.createReadStream('package.json');
  const writeStream = fs.createWriteStream('demo12.text');
  readStream.pipe(writeStream);
  return readStream;
}